﻿@model SCMS.UI.Models.AdvanceRequestModel
@{AjaxOptions ajaxOpts = new AjaxOptions
  {
      UpdateTargetId = "popup-page",
      LoadingElementId = "popup-loading",
      HttpMethod = "Post",
      Url = Url.Action("AuthorizeRFA"),
      OnBegin = "return VerifyBLBalance(" + Model.PaymentDetails.Count + ")",
      OnSuccess = "CenterPopup();LoadRequests();"
  };}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<div class="partialViewCard" style="max-width: 1200px; min-width: 900px">
    <div class="partialViewCardHeader"><h3>Request For Advance Authorization</h3></div>
    <br />   
    @using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
    {
        @Html.ValidationSummary(true)
        <h4 style="text-align: center;">@Model.RefNumber</h4> 
        <table width="98%" align="center" border="0" cellpadding="2" cellspacing="2" style=" border-bottom: 1px solid Grey;">
            <tr class="gridheader">
                <td colspan="3">
                    Subject/Purpose
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <b>@Model.Subject</b>
                    @Html.HiddenFor(x => x.Subject)
                </td>
            </tr>
            <tr class="gridheader">
                <td>
                    Payment To
                </td>
                <td>
                    Payment Terms
                </td>
                <td>
                    Payment Type
                </td>
            </tr>
            <tr>
                <td align="center">
                    @Model.Payee
                    @Html.HiddenFor(x => x.PaidTo)
                </td>
                <td align="center">
                    @Model.PaymentTerm
                    @Html.HiddenFor(x => x.PaymentTermId)
                </td>
                <td align="center">
                    @Model.PaymentType
                    @Html.HiddenFor(x => x.PaymentTypeId)
                </td>
            </tr>
            <tr class="gridheader">
                <td width="33%">
                    Date
                </td>
                <td width="33%">
                    Currency
                </td>
                <td width="34%">
                    Total Payment
                </td>
            </tr>
            <tr>
                <td align="center">
                    @Model.RequestDate.ToString("dd/MM/yyyy")
                    @Html.HiddenFor(m => m.RequestDate)
                    @Html.HiddenFor(m => m.Id)
                </td>
                <td align="center">
                    @Model.Currency
                    @Html.HiddenFor(x => x.CurrencyId, new { @id = "currencyId" })
                </td>
                <td align="center">
                    <b>@Model.TotalAdvance.ToString("#,##0.00")</b>
                    @Html.HiddenFor(m => m.TotalAdvance)
                </td>
            </tr>
        </table>
        <br />    
        <table width="98%" align="center" border="0" cellpadding="2" cellspacing="2">
            <tr class="gridheader">
                <td width="100%" colspan="2">
                    Detailed Description (Domestic/International Travel, Destinations, Dates of Travel...)
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    @Model.Description &nbsp;
                </td>
            </tr>
            <tr class="gridheader">
                <td width="100%" colspan="2">
                    Supporting Documents for RFA (TAF No., OR No., Quotation No., Contract No... )
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    @Model.DocDescription &nbsp;
                </td>
            </tr>
            <tr class="gridheader">
                <td  colspan="2">
                    Remarks
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    @Model.Remarks &nbsp;
                </td>
            </tr>
        </table>
        <p id="budgetCheckStatus"></p>
        <table class="cardTable" cellpadding="2">
            <tr class="gridheader">
                <th colspan="6" align="center">Payment Details</th>
            </tr>
            @if (Model.PaymentDetails.Count > 0)
            { 
                <tr class="gridheader">
                    <th align="center">#</th>
                    <th align="center">Request For</th>
                    <th align="center">Description</th>
                    <th align="center">Project No.</th>
                    <th align="center">Budget Line</th>
                    <th align="center">Amount</th>
                </tr>
                int count = 1;
                int num = 0; string pbDiv = ""; string rowId = "";
                for (int i = 0; i < Model.PaymentDetails.Count; i++)
                {
                    num = i + 1;
                    pbDiv = "PBlines" + num;
                    rowId = "row" + i;
                    <tr id="@rowId">
                        <td style="width: 5%; text-align: center;">
                            @count
                            @Html.HiddenFor(model => model.PaymentDetails[i].Id)
                        </td>
                        <td width="10%">@Model.PaymentDetails[i].AdvanceOption</td>
                        <td width="15%">@Model.PaymentDetails[i].Description</td>
                        <td style="width: 30%; text-align: center;">
                            @Html.DropDownListFor(model => model.PaymentDetails[i].ProjectId, Model.PaymentDetails[i].ProjectNos, new { @onchange = "onChangeProjectNoForRFA(this," + num + ")" })
                        </td>
                        <td style="width: 30%; text-align: center;">
                            <div id="@pbDiv">
                                @Html.DropDownListFor(model => model.PaymentDetails[i].BudgetLineID, Model.PaymentDetails[i].BudgetLines, new { onchange = "javascript:checkBalance4Review(this)" })
                            </div>
                        </td>
                        <td width="15%">
                            @Html.TextBoxFor(model => model.PaymentDetails[i].Amount, new { @style = "text-align:right;", @id = "totalPrice" + i, @onblur = "calculateTotalsRFP(" + i + ", " + Model.PaymentDetails.Count + ")" })
                            @Html.ValidationMessageFor(model => model.PaymentDetails[i].Amount)
                        </td>
                    </tr>
                }
                <tr>
                    <td align="right" colspan="6"><b>@Html.TextBoxFor(model => model.TotalAdvance, new { @style = "text-align:right;", @readonly = "readonly", @id = "totalVal" })</b></td>
                </tr>
            }
        </table>
        <br /> 
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid Black;
            border-collapse: collapse;">        
            <tr>
                <td align="right" width="35%" class="gridheader3"><b>Master Budget Currency&nbsp;</b></td>
                <td align="center" width="15%">
                    @Html.HiddenFor(model => model.MBCurrency, new { @id = "mbCurrencyId" })
                    @foreach (var curr in Model.Currencies)
                    {
                        if (curr.Value == Model.MBCurrency.ToString())
                        { 
                            @Html.Raw(curr.Text)
                        }
                    }
                </td>
                <td align="right" width="15%" class="gridheader3"><b>Total&nbsp;</b></td>
                <td width="15%">@Html.TextBoxFor(model => model.MBValue, new { @style = "text-align:right;", @id = "mbValue", @readonly = "readonly" })</td>
                <td width="20%" class="gridheader3">&nbsp;
                    <b>RFA Value</b>
                    <input type="hidden" id="origLocalValue" />
                    <input type="hidden" id="origFxValue" />
                </td>
            </tr> 
            <tr>
                <td align="right" width="35%" class="gridheader3"><b>Voucher No.&nbsp;</b></td>
                <td align="center" width="15%">@Html.TextBoxFor(model => model.VoucherNo, new { @disabled = "disabled" })</td>
                <td align="right" width="15%" class="gridheader3"><b>Account No.&nbsp;</b></td>
                <td>@Html.TextBoxFor(model => model.AccountNo, new { @disabled = "disabled" })</td>
                <td class="gridheader3">&nbsp;</td>
            </tr>   
        </table>
        <br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr class="gridheader">
                <td width="19%">
                    Authorization
                </td>
                <td width="27%">
                    RFP Prepared by
                </td>
                <td width="27%">
                    Finance Review/Approval of BL/PN
                </td>
                <td width="27%">
                    RFP Authorized by Manager/CD
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Name:
                </td>
                <td>
                    @if (Model.Preparer != null)
                    { 
                        @Model.Preparer.Person.FirstName 
                        @Html.Raw("&nbsp;")
                        @Model.Preparer.Person.OtherNames
                    }                
                </td>
                <td>
                    @if (Model.Approver != null)
                    { 
                        @Model.Approver.Person.FirstName 
                        @Html.Raw("&nbsp;")
                        @Model.Approver.Person.OtherNames
                    }
                </td>
                <td>
                    @if (Model.Authorizer != null)
                    { 
                        @Model.Authorizer.Person.FirstName 
                        @Html.Raw("&nbsp;")
                        @Model.Authorizer.Person.OtherNames
                    }
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Title:
                </td>
                <td>
                    @if (Model.Preparer != null)
                    { 
                        @Model.Preparer.Designation.Name
                    }                
                </td>
                <td>
                    @if (Model.Approver != null)
                    { 
                        @Model.Approver.Designation.Name
                    }
                </td>
                <td>
                    @if (Model.Authorizer != null)
                    { 
                        @Model.Authorizer.Designation.Name
                    }
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Date:
                </td>
                <td>
                    @Model.PreparedOn.ToString("dd/MM/yyyy hh:mm tt")
                </td>
                <td>
                    @if (Model.Approver != null)
                    { 
                        @Model.ApprovedOn.ToString("dd/MM/yyyy hh:mm tt")
                    }
                </td>
                <td>
                    @if (Model.Authorizer != null)
                    { 
                        @Model.AuthorizedOn.ToString("dd/MM/yyyy hh:mm tt")
                    }
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Signature:
                </td>
                <td>
                    @if (Model.Preparer != null && Model.Preparer.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.Preparer.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }                
                </td>
                <td>
                    @if (Model.Approver != null && Model.Approver.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.Approver.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                </td>
                <td>
                    @if (Model.Authorizer != null && Model.Authorizer.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.Authorizer.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                </td>
            </tr>
        </table>
        <table width="98%" align="center">
            <tr>
                <td width="50%" align="right"><input type="submit" class="btn green" value="Authorize" /></td>
                <td width="50%"><input type="button" class="btn green" value=" Reject " onclick="sendRequest('/RequestReview/LoadRejectRFA/@Model.Id', 'popup-page', 'popup-loading'); CenterPopup();" /></td>
            </tr>
        </table>
    }
</div>
